# coding:utf8
"""
题目描述：找出输入字符串中的重复字符，再根据ASCII码把重复的字符从小到大排序。

例如：输入ABCABCdd，输出ABCd。
"""


def de_duplication(str):
    dedup_str = ''
    for char in str:
        if not char in dedup_str:
            dedup_str += char

    return dedup_str


# str = input('请输入一串有重复字符的字符串：')
# print(de_duplication(str))

# class Solution(object):
#     def getIntersectionNode(self, headA, headB):
#         ha, hb = headA, headB
#         while ha != hb:
#             ha = ha.next if ha else headB
#             hb = hb.next if hb else headA
#         return ha
class Solution(object):
    def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> ListNode:
        p, q = headA, headB
        while p != q:
            if p:
                p = p.next
            else:
                p = headB
            if q:
                q = q.next
            else:
                q = headA
        return p


if __name__ == '__main__':
    s = Solution()
    a = [4, 1, 8, 4, 5]

    b = [5, 0, 1, 8, 4, 5]
    ha = s.getIntersectionNode(a, b)
    print(ha)
